package cn.wolfcode.crm.web.controller;


import cn.wolfcode.crm.domain.Permission;
import cn.wolfcode.crm.qo.PageResult;
import cn.wolfcode.crm.qo.QueryObject;

import cn.wolfcode.crm.service.IPermissionService;
import cn.wolfcode.crm.util.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("permission")
public class PermissionController {
    @Autowired
    private IPermissionService permissionService;

    //加载权限
    @RequestMapping("reload")
    @ResponseBody
    public Object reload() {
        permissionService.reload();
        //象征性返回
        return new JSONResult();
    }

    @RequestMapping("delete")
    @ResponseBody
    public Object delete(Long[] ids) {
        permissionService.deleteByPrimaryKey(ids);
        //象征性返回
        return new JSONResult();
    }

    //查询所有部门
    @RequestMapping("selectAll")
    @ResponseBody
    public Object selectAll() {
        //将数据转换成json格式
        List<Permission> permissions = permissionService.selectAll();

        return permissions;
    }

    @RequestMapping("query")
    @ResponseBody
    public Object list(@ModelAttribute("qo") QueryObject qo, Model model) {
        //将数据转换成json格式
        PageResult result = permissionService.queryForList(qo);

        return result;
    }

    @RequestMapping("view")

    public String list1() {

        return "/permission/list";
    }













}
